package com.sojoys.artifact.factory.bytebuff;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;

public class NettyByteBuff extends IByteBuff {
	ByteBuf buf = null;
	
	public NettyByteBuff(ByteBuf buf) {
		super();
		this.buf = buf;
	}
	
	protected void _writeByte(byte v) {
		buf.writeByte(v);
	}

	protected void _writeBytes(byte[] v) {
		buf.writeBytes(v);
	}
	
	protected byte _readByte(){
		return buf.readByte();
	}

	protected byte[] _readBytes(int readLength) {
		byte[] _byte = new byte[readLength];
		buf.readBytes(_byte);
		return _byte;
	}

	
	public byte[] toByte() {
		return ByteBufUtil.getBytes(buf);
	}


	@Override
	public IByteBuff reset() {
		buf.clear();
		return this;
	}
}
